package com.huaxindata.im.model.entity;

public class ChatVideoMessageBody extends ChatFileMessageBody {
    /**
     * 附件是否下载完成
     */
    public int downloadStatus;

    /**
     * 视频第一帧图片本地文件路径
     */
    public String thumbLocalPath;

    /**
     * 视频第一帧图片服务器远程文件路径
     */
    public String thumbRemotePath;

    /**
     * 时长, 秒为单位
     */
    public long duration;

    public ChatVideoMessageBody(int type) {
        super(type);
    }

    public ChatVideoMessageBody(String absolutePath) {
        super(Type.VIDEO);
        createFileMessageContent(absolutePath);
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    /**
     * 根据视频本地路径获取时长
     * @param localPath
     * @return  00:00
     */
    public String getVideoLength(String localPath) {
        long length = getMediaLength(localPath) / 1000;
        int min = (int) (length / 60);
        int second = (int) (length - min * 60);
        final StringBuilder sb = new StringBuilder();
        if (min > 10) {
            sb.append(min + ":");
        } else if (min > 0) {
            sb.append("0" + min + ":");
        } else {
            sb.append("00:");
        }
        if (second > 0) {
            sb.append("0" + second);
        } else if (second > 10) {
            sb.append("" + second);
        } else {
            sb.append("00");
        }
        return sb.toString();
    }

    @Override
    public String toString() {
        return "ChatVideoMessageBody{" +
                "downloadStatus=" + downloadStatus +
                ", thumbLocalPath='" + thumbLocalPath + '\'' +
                ", thumbRemotePath='" + thumbRemotePath + '\'' +
                ", duration=" + duration +
                '}';
    }
}
